$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeConvexMesh" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeMesh" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeSpline" );

SmitearWebGL.Objects.Parser.Collada.DaeGeometry = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.convex_mesh = null;
		this.mesh = null;
		this.spline = null;
		this.splines = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeGeometry" );
	}
	,
	read : function( node )
	{
		this._super( node );

		$LOG( "reading geometry: " + this.id );

		this.splines = [];

		var meshNode = this.getNode( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_CONVEX_MESH_ELEMENT );
		if( !meshNode ) {
			meshNode = this.getNode( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_MESH_ELEMENT );
			if( !meshNode) {
				meshNode = this.getNode( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_SPLINE_ELEMENT );
			}
		}
		
		$THROW( meshNode, "expected one of <convex_mesh>, <mesh> or <spline>!" );

		switch( meshNode.localName )
		{
			case SmitearWebGL.Objects.Parser.Collada.Const.DAE_CONVEX_MESH_ELEMENT:
				this.convex_mesh = new SmitearWebGL.Objects.Parser.Collada.DaeConvexMesh(this.document, this, meshNode );
				break;
				
			case SmitearWebGL.Objects.Parser.Collada.Const.DAE_MESH_ELEMENT:
				this.mesh = new SmitearWebGL.Objects.Parser.Collada.DaeMesh(this.document, this, meshNode );
				break;
				
			case SmitearWebGL.Objects.Parser.Collada.Const.DAE_SPLINE_ELEMENT:
				this.spline = new SmitearWebGL.Objects.Parser.Collada.DaeSpline(this.document, meshNode );
				var lst = this.getNodeList( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_SPLINE_ELEMENT );
				
				for( var i = 0; i < lst.length; i++ )
					this.splines.push(new SmitearWebGL.Objects.Parser.Collada.DaeSpline(this.document, lst[i]));
				break;
				
			default:
				break;
		}
	}
}
);